<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Netty WebSocket 时间服务器</title>
</head>
<body>
<br>
<script type="text/javascript">
	var socket;
	if(!window.WebSocket){
		window.WebSocket = window.MozWebSocket;
	}
	if(window.WebSocket){
		socket=new WebSocket("ws://localhost:8888/websocket");
		socket.onmessage=function(event){
			var ta = document.getElementById('responseText');
// 			ta.value="";
			ta.value+=event.data + "\r\n";
		}
		socket.onopen=function(event){
			var ta = document.getElementById('responseText');
			ta.value="打开WebSocket服务正常，浏览器支持WebSocket!";
		}
		socket.onclose=function(event){
			var ta = document.getElementById('responseText');
			ta.value="WebSocket 关闭!";
		}
	}else{
		alert("抱歉，您的浏览器不支持websocket协议!");
	}
	function send(message){
		if(!window.WebSocket){
			return;
		}
		if(socket.readyState==WebSocket.OPEN){
			socket.send(message);
		}else{
			alert("WebSocket没有连接成功!")
		}
		
	}
	</script>
	<form onsubmit="return false;">
		<input type="text" name="message" value="Netty 最佳实践"/>
		<input type="button" value=" 发送WebSocket请求消息" onclick="send(this.form.message.value)"/>
		<hr color="blue">
		<h3>服务器返回应答消息</h3>
		<textarea id="responseText" style="width:100%;height:500px" >
		
		</textarea>
	</form>
</body>
</html>